#!/usr/bin/env python3
"""
简化的Python测试脚本
"""

import sys
import os

def test_import():
    """测试模块导入"""
    print("测试模块导入...")
    try:
        # 添加库路径
        lib_path = os.path.join(os.path.dirname(__file__), '..', 'cmake-build-Release', 'lib')
        if lib_path not in sys.path:
            sys.path.insert(0, lib_path)
        
        import pyblink
        print("✓ pyblink模块导入成功")
        return True
    except ImportError as e:
        print(f"✗ pyblink模块导入失败: {e}")
        return False
    except Exception as e:
        print(f"✗ 其他错误: {e}")
        return False

def test_basic_functionality():
    """测试基本功能"""
    print("\n测试基本功能...")
    try:
        import pyblink
        
        # 测试枚举设备
        devices = pyblink.enumerate_devices()
        print(f"✓ 枚举设备成功，找到 {len(devices)} 个设备")
        
        for i, device in enumerate(devices):
            print(f"  设备 {i}: {device.name} (SN: {device.serialNumber})")
        
        # 测试错误字符串
        error_str = pyblink.get_error_string(pyblink.ErrorCode.SUCCESS)
        print(f"✓ 错误字符串获取成功: {error_str}")
        
        # 测试创建相机实例
        camera = pyblink.CameraCore()
        print("✓ 相机实例创建成功")
        
        # 测试配置结构
        color_profile = pyblink.ColorProfile()
        depth_profile = pyblink.DepthProfile()
        print("✓ 配置结构创建成功")
        
        return True
        
    except Exception as e:
        print(f"✗ 基本功能测试失败: {e}")
        return False

def main():
    """主测试函数"""
    print("=== pyblink简化测试 ===")
    
    # 运行测试
    tests = [
        test_import,
        test_basic_functionality,
    ]
    
    passed = 0
    total = len(tests)
    
    for test in tests:
        if test():
            passed += 1
        print()
    
    # 输出结果
    print("=== 测试结果 ===")
    print(f"通过: {passed}/{total}")
    
    if passed == total:
        print("✓ 所有测试通过！pyblink模块基本功能正常")
        return True
    else:
        print("✗ 部分测试失败")
        return False

if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)